#include <my_header.h>
// 正常取消示例
/* Usage: ./11_pthread_cancel2 */
void * func(void *arg){
    while(1){
        // 取消点函数
        printf("child thread printf \n");
    }
    printf("over... \n");
    return NULL;
}
int main()
{
    pthread_t  pid;
    int res = pthread_create(&pid, NULL, func, NULL);
    THREAD_ERROR_CHECK(res, "pthread_create");

    sleep(5);

    printf("main use cancel \n");
    // 取消一个执行中的线程
    int res_cancel = pthread_cancel(pid);
    THREAD_ERROR_CHECK(res_cancel, "pthread_cancel");

    int res_join = pthread_join(pid, NULL);
    THREAD_ERROR_CHECK(res_join, "pthread_join");

    return 0;
}
